const { DataTypes, Model } = require('sequelize');
const sequelize = require('../db/index.js');
class Product extends Model {}

Product.init({
    name: {
        type: DataTypes.STRING,
        allowNull: false,
    },
    description: {
        type: DataTypes.STRING,
    },
    price: {
        type: DataTypes.DECIMAL(10, 2),
        allowNull: false,
    },
}, {
    sequelize,
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at',
    deletedAt: 'deleted_at',
    paranoid: true,
    defaultScope: {
        order: [['created_at', 'DESC']], // 设置默认排序
    },
});

module.exports = Product;

const Category = require('./Category.js');
Product.belongsTo(Category, { foreignKey: 'category_id', allowNull: true, as: 'category' });